//package cn.t222.controller;
//
//import cn.t222.mapper.ProductRepository;
//import cn.t222.pojo.Product;
//import cn.t222.pojo.Result;
//import org.elasticsearch.index.query.QueryBuilders;
//import org.elasticsearch.search.sort.SortBuilders;
//import org.elasticsearch.search.sort.SortOrder;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.data.domain.Page;
//import org.springframework.data.domain.PageRequest;
//import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
//import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.web.bind.annotation.RestController;
//
//@RestController
//public class ProductController {
//    @Autowired
//    private ProductRepository porductRepository;
//
//    @GetMapping("/search")
//    public Result search(Integer start, String key) {
//        if(start ==  null) start = 0;
//        int size = 2;
//        NativeSearchQueryBuilder builder = new NativeSearchQueryBuilder();
//        builder.withQuery(QueryBuilders.multiMatchQuery(key,"name","body"));
//        builder.withSort(SortBuilders.fieldSort("id").order(SortOrder.DESC));
//        builder.withPageable(PageRequest.of(start, size));
//        Page<Product> products = porductRepository.search(builder.build());
//        return Result.ok("200","success", products);
//    }
//}
